$("#table").bootstrapTable({
    url: '/room/show',
    contentType: 'application/x-www-form-urlencoded',
    method: 'POST',
    toolbar: '#toolbar',
    sidePagination: 'server',
    pageNumber: 1,//当前页
    pageSize: 15,//每页条数
    pageList: [15, 50, 100, 'ALL'],
    dataType: 'json',//返回数据的类型
    /*detailView: true,*/
    cache: false,
    pagination: true,//使用分页
    /*showRefresh: true,//右上角刷新按钮
    showColumns: true,//右上角,列,列表*/
    // queryParams:function (params) {
    //     params["parentId"] = $("#parent-select").val();
    //     return params;
    // },
    classes: 'table table-hover table-striped',
    columns: [{
        checkbox: true
    }, {
        field: 'number',
        title: '序号',
        align: 'center',
        formatter: function (value, row, index) {
            return (index + 1);
        },
    }, {
        field: "id",
        title: "编号",
        align: "center"
    }, {
        field: "startdate",
        title: "开房时间",
        align: "center"
    }, {
        field: "enddate",
        title: "退房时间",
        align: "center"
    }, {
        field: "employee.name",
        title: "员工名称",
        align: "center"
    }, {
        field: "member.name",
        title: "会员姓名",
        align: "center"
    }, {
        field: "stateid",
        title: "状态",
        align: "center",
        formatter:function (value,row,index) {
            return row.state.name;
        }

    }, {
        field: "day",
        title: "天",
        align: "center"
    }, {
        field: "operator",
        title: "操作",
        align: "center",
        formatter: function (value, row, index) {
            var str = "<span class='glyphicon glyphicon-pencil' onclick='changeRoomOrder(" + row.id + ")'></span>&nbsp&nbsp;" +
                "<span class='glyphicon glyphicon-trash' onclick='deleteRoomOrder(" + row.id + ")'></span>&nbsp&nbsp;";

            return str;
        }
    }]
});

/**
  * 打开修改房间订单的模态框并显示默认数据
  * @param id 默认显示的房间订单编号
 * */
 function changeRoomOrder(id) {
    var url = "/room/getRoomOrderById";
    $("#changeRoomOrderModal").modal('show');
    $("#changeRoomOrderModal .modal-body").load(url, {id: id});
}

/**
 * 修改权限表单提交
 */
 function changeRoomOrderSubmit() {
    $.post("/room/getupdateRoomOrder",
         {
             "startdate": $("#startdate").val(),
             "enddate": $("#enddate").val(),
             "memberid": $("#memberid").val(),
             "employeeid": $("#employeeid").val(),
             "stateid": $("#stateid").val(),
             "day": $("#day").val()
         }, function (data) {
             if (data.updates) {
                 $("#table").bootstrapTable('refresh');
                 swal('修改成功!', '房间订单修改成功,请重新登录!', 'success');
                 $("#changeRoomOrderModal").modal('hide');
            } else {
                 swal('修改失败!', '房间订单修改失败,请重试!', 'error');
                 $("#changeRoomOrderModal").modal('hide');
             }
        }, "json");
}

 /**
  * 添加权限
 */
 function addRoomOrder() {
    $("#addroomorderModal").modal("show");
    $("#addroomorderModal .modal-body").load("/room/openAddRoomorder");
 }

 /**
  * 添加权限提交
  */
function addRoomOrderSubmit() {
    $.post("/room/addRoom",
        {
            "startdate": $("#startdate").val(),
             "enddate": $("#enddate").val(),
            "memberid": $("#memberid").val(),
            "employeeid": $("#employeeid").val(),
            "stateid": $("#stateid").val(),
            "day": $("#day").val()
        }, function (data) {
            if (data.result>0) {
                $("#table").bootstrapTable('refresh');
                 swal('添加成功!', '信息添加成功!', 'success');
                $("#addroomorderModal").modal('hide');
            } else {
                 swal('添加失败!', '信息添加失败!', 'error');
                 $("#addroomorderModal").modal('hide');
            }
        }, "json"
    );
 }

 /**
 * 根据编号删除房间订单信息
 * @param id 将要删除的房间订单信息编号
  */
 function deleteRoomOrder(id) {
    swal({
             title: "确认删除?",
             text: "删除房间信息吗？信息删除无法找回",
            type: "warning",
             showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确认",
            cancelButtonText: "取消",
            closeOnConfirm: false,
            closeOnCancel: false
         },
         function (isConfirm) {
           if (isConfirm) {
                $.post("/super/delPrivilegeById", {"id": id}, function (data) {
                  if (data.true>= 1) {
                        swal("删除成功!", "房间订单信息删除成功!共删除了" + data.true + "条房间信息!", "success");
                     } else {
                        swal("删除失败!", "房间订单信息删除失败，请重试!");
                     }
                     }, "json");
            }else{
                 swal("删除失败!", "您取消了删除操作!)", "error");
            }
         });
 }

// /**
//  * 根据父权限编号获取权限
//  */
// function getPrivilegeByParentId() {
//     $("#table").bootstrapTable("refresh");
// }